package com.headingdata.exercise;

import java.util.Random;

public class Test2 {

    public static void main(String[] args) {
        // 生成指定位数的验证码，验证码包含大、小写字母及数字
        String code = createCode(6);
        System.out.println(code);
    }
    public static String createCode(int n){
        Random r = new Random();
        String code = "";
        for (int i =0; i < n; i++){
            int type = r.nextInt(3);
            switch (type){
                case 0: //数字
                    code += r.nextInt(10);break;
                case 1: //大写字母
                    code += (char)r.nextInt(65,91);break;
                case 2: //小写字母
                    code += (char)r.nextInt(97,123);break;
            }
        }
        return code;
    }
}
